package com.qumitech.visualnovel.controller.rest.novel;

import java.util.*;

import com.alibaba.fastjson.*;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.qumitech.visualnovel.model.common.BaseResponse;
import com.qumitech.visualnovel.service.novel.BookService;
import com.qumitech.visualnovel.model.dto.*;

@RestController
@Api(value = "小说模块", description = "小说相关api")
public class BookRest {
    @Autowired
    private BookService bookService;

    @ApiOperation(value = "修改小说", notes = "修改小说")
    @PostMapping("/api/book")
    public BaseResponse update(@RequestBody List<BookUpdateDTO> body) {
        return bookService.update(body);
    }

    @ApiOperation(value = "查询书籍分级信息", notes = "查询书籍分级信息")
    @GetMapping("/api/book/rating/{book_id}")
    public BaseResponse getBookRating(@PathVariable(name = "book_id") Long bookId) {
        return bookService.getBookRating(bookId);
    }

    @ApiOperation(value = "修改书籍分级信息", notes = "修改书籍分级信息")
    @PutMapping("/api/book/rating")
    public BaseResponse updateBookRating(@RequestBody BookRatingDTO body) {
        return bookService.updateBookRating(body);
    }

    @ApiOperation(value = "查询小说列表", notes = "查询小说列表")
    @GetMapping("/api/book/list")
    public BaseResponse list(BookQueryDTO param) {
        return bookService.list(param);
    }

    @ApiOperation(value = "预览小说", notes = "预览小说")
    @GetMapping("/api/book/preview")
    public BaseResponse preview(BookPreviewDTO param) {
        return bookService.preview(param);
    }

    @ApiOperation(value = "添加小说推荐", notes = "添加小说推荐")
    @PutMapping("/api/book/recommend")
    public BaseResponse addBookRecommend(@RequestBody BookRecommendAddDTO body) {
        return bookService.addBookRecommend(body);
    }

    @ApiOperation(value = "删除小说推荐", notes = "删除小说推荐")
    @DeleteMapping("/api/book/recommend/{id}")
    public BaseResponse delBookRecommend(@PathVariable(name = "id") Long id) {
        return bookService.delBookRecommend(id);
    }

    @ApiOperation(value = "修改小说推荐", notes = "修改小说推荐")
    @PostMapping("/api/book/recommend/{id}")
    public BaseResponse updateBookRecommend(@PathVariable(name = "id") Long id, @RequestBody BookRecommendAddDTO body) {
        return bookService.updateBookRecommend(id, body);
    }

    @ApiOperation(value = "获取小说推荐列表", notes = "获取小说推荐列表")
    @GetMapping("/api/book/recommend/list")
    public BaseResponse getBookRecommend(BookRecommendQueryDTO param) {
        return bookService.getBookRecommend(param);
    }

    @ApiOperation(value = "获取小说名称选项", notes = "获取小说名称选项")
    @GetMapping("/api/book/title/option")
    public BaseResponse getBookNameOption(
            @RequestParam(value = "publishStates", required = false) List<String> publishStates,
            @RequestParam(value = "category", required = false) String category) {
        return bookService.getBookNameOption(publishStates, category);
    }

    @ApiOperation(value = "获取小说评论列表", notes = "获取小说评论列表")
    @GetMapping("/api/book/comment/list")
    public BaseResponse getBookComment(BookCommentQueryDTO param) {
        return bookService.getBookComment(param);
    }

    @ApiOperation(value = "导入文本小说", notes = "导入文本小说")
    @PostMapping("/api/book/textnovel/import")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件列表", required = true)
    })
    public BaseResponse textNovelImport(HttpServletRequest request) {
        return bookService.textNovelImport(request);
    }

    @ApiOperation(value = "文本小说上下架", notes = "文本小说上下架")
    @PostMapping("/api/book/textnovel/online/{if_online}")
    public BaseResponse textNovelOnline(@PathVariable("if_online") Boolean ifOnline, @RequestBody List<Long> bookIdList) {
        return bookService.textNovelOnline(ifOnline, bookIdList);
    }

    @ApiOperation(value = "获取文本小说章节内容", notes = "获取文本小说章节内容")
    @GetMapping("/api/book/{chapter_id}/frames")
    public BaseResponse getChapterFrames(@PathVariable("chapter_id") Long chapterId) {
        return bookService.getChapterFrames(chapterId);
    }

    @ApiOperation(value = "修改小说章节内容", notes = "修改小说章节内容")
    @PostMapping("/api/book/{chapter_id}/frames")
    public BaseResponse updateChapterFrames(@PathVariable("chapter_id") Long chapterId, @RequestBody List<BookFrameUpdateDTO> body) {
        return bookService.updateChapterFrames(chapterId, body);
    }

    @ApiOperation(value = "添加小说的分类配置", notes = "添加小说的分类配置")
    @PutMapping("/api/book/classify/conf")
    public BaseResponse addBookClissfyConf(@RequestBody BookClissfyConfDTO body) {
        return bookService.addBookClissfyConf(body);
    }

    @ApiOperation(value = "删除小说的分类配置", notes = "删除小说的分类配置")
    @DeleteMapping("/api/book/classify/conf/{classifyId}")
    public BaseResponse delBookClissfyConf(@PathVariable("classifyId") Long classifyId) {
        return bookService.delBookClissfyConf(classifyId);
    }

    @ApiOperation(value = "更新小说的分类配置", notes = "更新小说的分类配置")
    @PostMapping("/api/book/classify/conf")
    public BaseResponse updateBookClissfyConf(@RequestBody List<BookClissfyConfUpdateDTO> body) {
        return bookService.updateBookClissfyConf(body);
    }

    @ApiOperation(value = "获取小说分类记录列表", notes = "获取小说分类记录列表")
    @GetMapping("/api/book/classify/record")
    public BaseResponse getBookClissfyRecord(@RequestParam(value = "if_recommend", required = true) Boolean ifRecommend,
                                             @RequestParam(value = "classifyType", required = true, defaultValue = "1") Integer classifyType) {
        return bookService.getBookClissfyRecord(ifRecommend,classifyType);
    }

    @ApiOperation(value = "添加小说的分类记录", notes = "添加小说的分类记录")
    @PutMapping("/api/book/classify/record/{classifyId}")
    public BaseResponse addBookClissfyRecord(@PathVariable("classifyId") Long classifyId, @RequestBody List<BookClissfyRecordAddDTO> body) {
        return bookService.addBookClissfyRecord(classifyId, body);
    }

    @ApiOperation(value = "修改小说分类记录的顺序", notes = "修改小说分类记录的顺序")
    @PostMapping("/api/book/classify/record/order")
    public BaseResponse updateBookClissfyRecordOrder(@RequestBody List<BookClissfyRecordUpdateDTO> body) {
        return bookService.updateBookClissfyRecordOrder(body);
    }

    @ApiOperation(value = "删除小说的分类记录", notes = "删除小说的分类记录")
    @DeleteMapping("/api/book/classify/record/{recordId}")
    public BaseResponse delBookClissfyRecord(@PathVariable("recordId") Long recordId) {
        return bookService.delBookClissfyRecord(recordId);
    }

    @ApiOperation(value = "获取书籍统计信息", notes = "获取书籍统计信息")
    @GetMapping("/api/book/statistic/list")
    public BaseResponse getBookStatisticList(BookStatisticQueryDTO param) {
        return bookService.getBookStatisticList(param);
    }
}
